//
//  NSMutableString+BPCrash.m
//  BPCrashDemo
//
//  Created by SiYugui on 2019/12/30.
//  Copyright © 2019年 SiYugui. All rights reserved.
//

#import "NSMutableString+BPCrash.h"
#import "NSObject+BPSwizzle.h"
#import "BPCrashLog.h"
@implementation NSMutableString (BPCrash)
+(void)avoidMutableStringCrashExchangeMethod{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class stringClass = NSClassFromString(@"__NSCFString");
        [self exchangeInstanceMethod:stringClass method1:@selector(replaceCharactersInRange:withString:) method2:@selector(__replaceCharactersInRange:withString:)];
        
        [self exchangeInstanceMethod:stringClass method1:@selector(insertString:atIndex:) method2:@selector(__insertString:atIndex:)];
        
        [self exchangeInstanceMethod:stringClass method1:@selector(deleteCharactersInRange:) method2:@selector(__deleteCharactersInRange:)];
    });
}



-(void)__replaceCharactersInRange:(NSRange)range withString:(NSString *)aString{
    @try {
        [self __replaceCharactersInRange:range withString:aString];
    } @catch (NSException *exception) {
        [BPCrashLog noteErrorWithException:exception attachedToDo:BPCrashDefaultReturnIgnore];
    } @finally {
        
    }
}

-(void)__insertString:(NSString *)aString atIndex:(NSUInteger)loc{
    @try {
        [self __insertString:aString atIndex:loc];
    } @catch (NSException *exception) {
        [BPCrashLog noteErrorWithException:exception attachedToDo:BPCrashDefaultReturnIgnore];
    } @finally {
        
    }
}

-(void)__deleteCharactersInRange:(NSRange)range{
    @try {
        [self __deleteCharactersInRange:range];
    } @catch (NSException *exception) {
        [BPCrashLog noteErrorWithException:exception attachedToDo:BPCrashDefaultReturnIgnore];
    } @finally {
        
    }
}
@end
